package com.jzo2o.foundations.controller.operation;

import com.jzo2o.common.model.PageResult;
import com.jzo2o.foundations.model.dto.request.ServePageQueryReqDTO;
import com.jzo2o.foundations.model.dto.request.ServeUpsertReqDTO;
import com.jzo2o.foundations.model.dto.response.ServeResDTO;
import com.jzo2o.foundations.service.IServeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;

@RestController("operationServeController")//因为每个C端都有一个这样的接口，所以需要区分
@RequestMapping("/operation/serve")
@Api(tags = "运营端-区域服务接口管理")
public class ServeController {
    @Resource
    private IServeService serveService;
    @GetMapping("/page")
    @ApiOperation(value = "分页查询服务")
    public PageResult<ServeResDTO> page(ServePageQueryReqDTO servePageQueryReqDTO){
        return serveService.page(servePageQueryReqDTO);
    }

    @PostMapping("/batch")
    @ApiOperation(value = "批量新增服务")
    public void add(@RequestBody List<ServeUpsertReqDTO> serveUpsertReqDTOList){
        serveService.batchAdd(serveUpsertReqDTOList);
    }


//    http://localhost:3000/api/foundations/operation/serve/1909629493891354626?price=68.00
    @PutMapping("/{id}")
    @ApiOperation(value = "修改服务价格")
    public void update(@PathVariable Long id, @RequestParam("price") BigDecimal price){
        serveService.update(id, price);
    }

//    http://localhost:3000/api/foundations/operation/serve/onSale/1909629493891354626
    @PutMapping("/onSale/{id}")
    @ApiOperation(value = "上架服务")
    public void onSale(@PathVariable Long id){
        serveService.onSale(id);
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除服务")
    public void delete(@PathVariable Long id){
        serveService.delete(id);
    }

    @PutMapping("/offSale/{id}")
    @ApiOperation(value = "下架服务")
    public void offSale(@PathVariable Long id){
        serveService.offSale(id);
    }

    @PutMapping("/onHot/{id}")
    @ApiOperation(value = "设置热门服务")
    public void onHot(@PathVariable Long id){
        serveService.onHot(id);
    }
    @PutMapping("/offHot/{id}")
    @ApiOperation(value = "取消热门服务")
    public void offHot(@PathVariable Long id){
        serveService.offHot(id);
    }

}
